package com.travel.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.travel.dto.LookForCarDto;
import com.travel.pojo.Cars;
import com.travel.service.CarsService;
import com.travel.mapper.CarsMapper;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author rjq51
 * @description 针对表【cars】的数据库操作Service实现
 * @createDate 2023-05-11 10:11:34
 */
@Service
public class CarsServiceImpl extends ServiceImpl<CarsMapper, Cars>
        implements CarsService {

    @Autowired
    private CarsMapper carsMapper;

    /**
     * 根据条件查询符合条件的车辆
     *
     * @param
     * @return
     */
    @Override
    public List<Cars> FastCarSelection(LookForCarDto lookForCarDto) {
        QueryWrapper<Cars> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq(!StringUtils.isEmpty(lookForCarDto.getCarType()), "car_type", lookForCarDto.getCarType())
                .eq(!StringUtils.isEmpty(lookForCarDto.getCarBrand()), "car_brand", lookForCarDto.getCarBrand())
                .eq(!StringUtils.isEmpty(lookForCarDto.getDrivingStyle()), "driving_style", lookForCarDto.getDrivingStyle())
                .eq(lookForCarDto.getSeats() != null && lookForCarDto.getSeats() != 0 , "seats", lookForCarDto.getSeats());
        return carsMapper.selectList(queryWrapper);
    }
}




